package com.wuwei.aliocr.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuwei.aliocr.domain.LessonRecord;
import com.wuwei.aliocr.domain.ShangKeRiQi;
import com.wuwei.aliocr.domain.Subject;
import com.wuwei.aliocr.mapper.ShangKeRiQiMapper;
import com.wuwei.aliocr.mapper.SubjectMapper;
import com.wuwei.aliocr.service.ExcelService;
import com.wuwei.aliocr.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {

    @Resource
    private ShangKeRiQiMapper shangKeRiQiMapper;

    @Autowired
    private CommonUtils commonUtils;

    @Resource
    private SubjectMapper subjectMapper;

    //生成相应的excel表格,对应这公司的排班的格式

    @Override
    public void addExcel(String date, String weekend) {

    }


    //生成相应的excel表格,对应这公司的排班的格式

    /**
     * 输入科目，科目的课时和开始上课的时间，就能自动生成课表
     * @param subject
     * @param hours
     * @param inputDate
     */
    @Override
    public void getExcel(String subject, Integer hours, String inputDate,String setMorningOrAfternoon) {
//        Integer size = hours/2;
//        //从数据库中查询到工作日的列表
//        LambdaQueryWrapper<ShangKeRiQi> queryWrapper = new LambdaQueryWrapper<>();
//        List<ShangKeRiQi> workdays = shangKeRiQiMapper.selectList(queryWrapper);
//        ArrayList<LessonRecord> workdayArrayList = new ArrayList<>();
//        workdays.forEach(a -> {
//            String date = a.getDate();
//            //遍历找到和输入的日期匹配的参数
//            if (commonUtils.afterDay(date,inputDate)) {
//                a.setDate(date);
//                for (int i = 0; i < 4; i++) {
//                    LessonRecord workday = new LessonRecord();
//                    String substring = date.substring(date.indexOf("年") + 1);
//                    workday.setDate(substring);
//                    workday.setWeekend(a.getWeekend());
//                    workday.setHours("2");
//                    workday.setPosition("301");
//                    workday.setType("理论");
//                    if (i%4 == 0) {
//                        workday.setTime("8:30-10:00");
//                        workday.setMorningOrAfternoon("上午");
//                    }else if (i%4 == 1) {
//                        workday.setTime("10:30-12:30");
//                        workday.setMorningOrAfternoon("上午");
//                    }else if (i%4 == 2) {
//                        workday.setTime("13:30-15:30");
//                        workday.setMorningOrAfternoon("下午");
//                    }else {
//                        workday.setTime("15:30-17:30");
//                        workday.setMorningOrAfternoon("下午");
//                    }
////                    if (setMorningOrAfternoon.equals("上午")) {//表明该章节是从上午开始的
////
////                    }else {//表明该章节是从下午开始的
////
////                    }
//                    //当课时达到就不需要再排下去了
//                    if (workdayArrayList.size()<size) {
//                        workdayArrayList.add(workday);
//                    }
//                }
//            }
//        });
//        //这里数据有点过多了，当学时超过一定的时候就不需要添加数据了
//        System.out.println(workdayArrayList.size());
//        String filename = "D:/workday/work5.xlsx";
//        try(ExcelWriter excelWriter = EasyExcel.write(filename, LessonRecord.class).build()){
//            // 这里注意 如果同一个sheet只要创建一次
//            WriteSheet writeSheet = EasyExcel.writerSheet(subject).build();
//            excelWriter.write(workdayArrayList,writeSheet);
//        }
    }

    /**
     * 完成填写好课表的框架，当上课时间确定好，填充好每个科目的框架，包括上课时间和上课的内容
     *
     * @param date 开班日期 格式为2023年09月19日这种的，注意是09月，不是9月，这里的0不能省略
     * @param type 班级的类型，现在支持PA或PA
     */
    @Override
    public void writeExcel(String date, String type) {
        //先把时间填充了
        HashMap<String, ArrayList<LessonRecord>> hashMap = this.writeExcelTime(date, type);

        //再填充课程安排
        hashMap = this.writeExcelClass(hashMap,type);

        String filename = "D:/work5.xlsx";

        ArrayList<LessonRecord> m1LessonRecordArrayList = hashMap.get("m1LessonRecordArrayList");
        ArrayList<LessonRecord> m2LessonRecordArrayList = hashMap.get("m2LessonRecordArrayList");
        ArrayList<LessonRecord> m3LessonRecordArrayList = hashMap.get("m3LessonRecordArrayList");
        ArrayList<LessonRecord> m5ORm6LessonRecordArrayList = hashMap.get("m5oRm6WorkdayArray");
        ArrayList<LessonRecord> m7LessonRecordArrayList = hashMap.get("m7LessonRecordArrayList");
        ArrayList<LessonRecord> m8LessonRecordArrayList = hashMap.get("m8LessonRecordArrayList");
        m8LessonRecordArrayList.forEach(a-> {
            a.setType("实操");
            a.setPosition("实操基地");
        });

        try(ExcelWriter excelWriter = EasyExcel.write(filename, LessonRecord.class).build()){
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet1 = EasyExcel.writerSheet("M1").build();
            excelWriter.write(m1LessonRecordArrayList,writeSheet1);
            WriteSheet writeSheet2 = EasyExcel.writerSheet("M2").build();
            excelWriter.write(m2LessonRecordArrayList,writeSheet2);
            WriteSheet writeSheet3 = EasyExcel.writerSheet("M3").build();
            excelWriter.write(m3LessonRecordArrayList,writeSheet3);
            if (type.equals("PA")) {
                WriteSheet writeSheet6 = EasyExcel.writerSheet("M6").build();
                excelWriter.write(m5ORm6LessonRecordArrayList,writeSheet6);
            }else if (type.equals("TA")){
                WriteSheet writeSheet5 = EasyExcel.writerSheet("M5").build();
                excelWriter.write(m5ORm6LessonRecordArrayList,writeSheet5);
            }
            WriteSheet writeSheet7 = EasyExcel.writerSheet("M7").build();
            excelWriter.write(m7LessonRecordArrayList,writeSheet7);
            WriteSheet writeSheet8 = EasyExcel.writerSheet("M8").build();
            excelWriter.write(m8LessonRecordArrayList,writeSheet8);
        }

    }



    /**
     * 填充课程安排，返回课程安排的HashMap<String, ArrayList<LessonRecord>>
     * @param hashMap
     * @return
     */
    private HashMap<String, ArrayList<LessonRecord>> writeExcelClass(HashMap<String, ArrayList<LessonRecord>> hashMap, String type) {
        //M1
        ArrayList<LessonRecord> m1LessonRecordArrayList = hashMap.get("m1LessonRecordArrayList");
        setM1Class(m1LessonRecordArrayList);
        hashMap.put("m1LessonRecordArrayList", m1LessonRecordArrayList);
        //M2
        ArrayList<LessonRecord> m2LessonRecordArrayList = hashMap.get("m2LessonRecordArrayList");
        setM2Class(m2LessonRecordArrayList);
        hashMap.put("m2LessonRecordArrayList", m2LessonRecordArrayList);
        //M3
        ArrayList<LessonRecord> m3LessonRecordArrayList = hashMap.get("m3LessonRecordArrayList");
        setM3Class(m3LessonRecordArrayList);
        hashMap.put("m3LessonRecordArrayList", m3LessonRecordArrayList);
        //M5或M6
        ArrayList<LessonRecord> m5ORm6LessonRecordArrayList = hashMap.get("m5ORm6LessonRecordArrayList");
        LessonRecord m3LessonRecord = findTheLastWorkDayAndTheTestDay(m3LessonRecordArrayList);
        if (type.equals("PA")) {
            //M6
            setM6Class(m5ORm6LessonRecordArrayList, m3LessonRecord);
        }else if (type.equals("TA")) {
            //M5
            setM5Class(m5ORm6LessonRecordArrayList, m3LessonRecord);
        }
        hashMap.put("m5oRm6WorkdayArray", m5ORm6LessonRecordArrayList);
        String m7TestTime = "";
        if (type.equals("TA")) {
            LessonRecord lessonRecord = m5ORm6LessonRecordArrayList.get(m5ORm6LessonRecordArrayList.size() - 3);
            String weekend = lessonRecord.getWeekend();
            if (weekend.equals("星期六")) {
                m7TestTime = "M5考试影响M7";
                //如果M5的倒数第三节课是在星期六上，说明当天上完课不安排考试，那么M7上课期间需要留出时间用来考试
            }else {
                m7TestTime = "M5考试不影响M7";
                //如果M5的倒数第三节课不是在星期六上，说明当天上完课就安排考试，对于M7上课没有影响
            }
        }else {
            //如果是M5,需要知道倒数第二个元素（最后一节课）和倒数第一个元素（考试）之间在数据库中能否查到元素，如果还能查到说明M7先上课在考试
            //如果查不到，说明M7先考试再上课
            //获取现在的年份
            LessonRecord m5OrM6LessonRecord = findTheLastWorkDayAndTheTestDay(m5ORm6LessonRecordArrayList);
            if (m5OrM6LessonRecord == null) {
                //表明查不到，说明后面的M7是先考试，在上课，在M7上课期间不用安排考试时间
                m7TestTime="M6考试不影响M7";
            }else {
                //如果查到了，说明M7是先上课，中途需要安排考试时间
                m7TestTime="M6考试影响M7";
            }
        }

        //M7
        ArrayList<LessonRecord> m7LessonRecordArrayList = hashMap.get("m7LessonRecordArrayList");
        m7LessonRecordArrayList.forEach(a-> {
            a.setType("实操");
            a.setPosition("310教室");
        });
        setM7Class(m7LessonRecordArrayList,type,m7TestTime);
        hashMap.put("m7LessonRecordArrayList", m7LessonRecordArrayList);
        //M8
        ArrayList<LessonRecord> m8LessonRecordArrayList = hashMap.get("m8LessonRecordArrayList");
        setM8Class(m8LessonRecordArrayList);
        hashMap.put("m8LessonRecordArrayList", m8LessonRecordArrayList);
        return hashMap;
    }

    private LessonRecord findTheLastWorkDayAndTheTestDay(ArrayList<LessonRecord> m5ORm6LessonRecordArrayList) {
        Integer nowYear = commonUtils.nowYear();
        LessonRecord testLessonRecord = m5ORm6LessonRecordArrayList.get(m5ORm6LessonRecordArrayList.size() - 1);
        Date date1 = testLessonRecord.getDate();
        String testWorkdayDate = commonUtils.mySqlDateFormatDateDashToString(date1);
        testWorkdayDate = nowYear+"年"+testWorkdayDate;
        LessonRecord lastClassLessonRecord = m5ORm6LessonRecordArrayList.get(m5ORm6LessonRecordArrayList.size() - 2);
        String lastClassWorkdayDate = commonUtils.mySqlDateFormatDateDashToString(lastClassLessonRecord.getDate());
        lastClassWorkdayDate = nowYear +"年"+lastClassWorkdayDate;
        Date formattedTestWorkdayDate = commonUtils.mySqlDateFormatStringOfDashToDate(testWorkdayDate);
        Date formattedLastClassWorkdayDate = commonUtils.mySqlDateFormatStringOfDashToDate(lastClassWorkdayDate);
        return shangKeRiQiMapper.getWorkdayBetweenLastClassAndTestday(formattedLastClassWorkdayDate,formattedTestWorkdayDate);
    }


    /**
     * 设置M8的课程安排
     * @param m8LessonRecordArrayList
     */
    private void setM8Class(ArrayList<LessonRecord> m8LessonRecordArrayList) {
        String model = "M8";
        List<Subject> subjects = getSubjectModel(model);
        for (int i = 0; i < m8LessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord = m8LessonRecordArrayList.get(i);
            lessonRecord.setSubject(subjects.get(i).getName());
        }
    }

    /**
     * 设置M7的课程安排
     * @param m7LessonRecordArrayList
     * @param m7TestTime 表示M5或者M6的考试是否会影响到M7
     */
    private void setM7Class(ArrayList<LessonRecord> m7LessonRecordArrayList, String type, String m7TestTime) {
        String model = "M7";
        List<Subject> subjects = getSubjectModel(model);
            //TODO PA和TA考试时间是不一样的，因此需要分开计算
            if (type.equals("PA")) {
                if (m7TestTime.equals("M6考试影响M7")) {
                    //M6考试如果是放在周一，那么M7就是周六上午开课
                    for (int i = 0; i < m7LessonRecordArrayList.size(); i++) {
                        LessonRecord lessonRecord = m7LessonRecordArrayList.get(i);
                        if (i<4) {
                            lessonRecord.setSubject(subjects.get(i).getName());
                        }else if(i>=4&i<6){
                            lessonRecord.setSubject("/");
                            lessonRecord.setType("/");
                            lessonRecord.setPosition("/");
                            lessonRecord.setHours("/");
                        }else {
                            lessonRecord.setSubject(subjects.get(i-2).getName());
                        }
                    }
                }else {
                    //否则M7是下午开课
                    for (int i = 0; i < m7LessonRecordArrayList.size(); i++) {
                        LessonRecord lessonRecord = m7LessonRecordArrayList.get(i);
                        if(i<2){
                            lessonRecord.setSubject("/");
                            lessonRecord.setType("/");
                            lessonRecord.setPosition("/");
                            lessonRecord.setHours("/");
                        }else {
                            lessonRecord.setSubject(subjects.get(i-2).getName());
                        }
                    }
                }
            }else {
                /**
                 * 如果是TA有两种情况
                 * 1.如果M5是当天下午考试的话，那么M7课程全程没有空缺
                 * 2，如果M5结束的时候刚好是周六，是后面再考的话，那么M7的下午是处于没有课的状态的
                 */
                //如果M5是下个周一考试，那么M7就是上到一半再去考试
                if (m7TestTime.equals("M5考试影响M7")) {
                    for (int i = 0; i < m7LessonRecordArrayList.size(); i++) {
                        LessonRecord lessonRecord = m7LessonRecordArrayList.get(i);
                        if (i<2) {
                            lessonRecord.setSubject(subjects.get(i).getName());
                        }else if (i>=2&&i<4) {
                            lessonRecord.setSubject("/");
                            lessonRecord.setType("/");
                            lessonRecord.setPosition("/");
                            lessonRecord.setHours("/");
                        }
                        else {
                            lessonRecord.setSubject(subjects.get(i-2).getName());
                        }
                    }
                }else {
                    //否则M7就是直接上完全程
                    for (int i = 0; i < m7LessonRecordArrayList.size()-2; i++) {
                        LessonRecord lessonRecord = m7LessonRecordArrayList.get(i);
                        lessonRecord.setSubject(subjects.get(i).getName());
                    }
                    for (int i = m7LessonRecordArrayList.size()-2; i < m7LessonRecordArrayList.size(); i++) {
                        LessonRecord lessonRecord = m7LessonRecordArrayList.get(i);
                        lessonRecord.setSubject("/");
                        lessonRecord.setType("/");
                        lessonRecord.setPosition("/");
                        lessonRecord.setHours("/");
                    }
                }
            }
//        }
    }

    /**
     * 设置M6的课程安排
     * @param m5ORm6LessonRecordArray
     */
    private void setM6Class(ArrayList<LessonRecord> m5ORm6LessonRecordArray, LessonRecord m3LessonRecord) {
        String model = "M6";
        String testString = "M6模块考试";
        List<Subject> subjects = getSubjectModel(model);
        if (m3LessonRecord ==null) {
            for (int i = 0; i < m5ORm6LessonRecordArray.size(); i++) {
                LessonRecord lessonRecord = m5ORm6LessonRecordArray.get(i);
                if (i <2) {
                    lessonRecord.setSubject(subjects.get(i).getName());
                }
                //i<m5ORm6LessonRecordArray.size()-3
                else if (i>3&&i< m5ORm6LessonRecordArray.size()-2) {
                    Subject subject = subjects.get(i-2);
                    lessonRecord.setSubject(subject.getName());
                }
                else if (i == m5ORm6LessonRecordArray.size()-2) {
                    lessonRecord.setSubject("自习");
                    lessonRecord.setType("/");
                }
                else if (i == m5ORm6LessonRecordArray.size()-1)  {
                    lessonRecord.setSubject(testString);
                    lessonRecord.setType("/");
                    lessonRecord.setHours("/");
                    lessonRecord.setPosition("303考场");
                }else {
                    lessonRecord.setSubject("/");
                    lessonRecord.setType("/");
                    lessonRecord.setPosition("/");
                    lessonRecord.setHours("/");
                }
            }
        }else {
            for (int i = 0; i < m5ORm6LessonRecordArray.size(); i++) {
                LessonRecord lessonRecord = m5ORm6LessonRecordArray.get(i);
                if (i <6) {
                    lessonRecord.setSubject(subjects.get(i).getName());
                }
                //i<m5ORm6LessonRecordArray.size()-3
                else if (i>7&&i< m5ORm6LessonRecordArray.size()-2) {
                    Subject subject = subjects.get(i-2);
                    lessonRecord.setSubject(subject.getName());
                }
                else if (i == m5ORm6LessonRecordArray.size()-2) {
                    lessonRecord.setSubject("自习");
                    lessonRecord.setType("/");
                }
                else if (i == m5ORm6LessonRecordArray.size()-1)  {
                    lessonRecord.setSubject(testString);
                    lessonRecord.setType("/");
                    lessonRecord.setHours("/");
                    lessonRecord.setPosition("303考场");
                } else {
                    lessonRecord.setSubject("/");
                    lessonRecord.setType("/");
                    lessonRecord.setPosition("/");
                    lessonRecord.setHours("/");
                }
            }
        }
    }

    /**
     * 设置M的课程安排
     * @param m5ORm6LessonRecordArrayList
     */
    private void setM5Class(ArrayList<LessonRecord> m5ORm6LessonRecordArrayList, LessonRecord m3LessonRecord) {
        String model = "M5";
        String testString = "M5模块考试";
        List<Subject> subjects = getSubjectModel(model);
        if (m3LessonRecord ==null) {
            for (int i = 0; i < m5ORm6LessonRecordArrayList.size(); i++) {
                LessonRecord lessonRecord = m5ORm6LessonRecordArrayList.get(i);
                if (i < 2) {
                    lessonRecord.setSubject(subjects.get(i).getName());
                }
                else{
                    if (m5ORm6LessonRecordArrayList.size() == 49) {
                        if (i < 4){
                            lessonRecord.setSubject("/");
                            lessonRecord.setType("/");
                            lessonRecord.setPosition("/");
                            lessonRecord.setHours("/");
                        }
                        else if (i < m5ORm6LessonRecordArrayList.size() - 4) {
                            Subject subject = subjects.get(i - 2);
                            lessonRecord.setSubject(subject.getName());
                        } else if (i != m5ORm6LessonRecordArrayList.size() - 1) {
                            lessonRecord.setSubject("自习");
                            lessonRecord.setType("/");
                        } else {
                            lessonRecord.setSubject(testString);
                            lessonRecord.setType("/");
                            lessonRecord.setTime("14:00-16:00");
                            lessonRecord.setHours("/");
                            lessonRecord.setPosition("303考场");
                        }
                    } else {
                        if (i > 3 && i < m5ORm6LessonRecordArrayList.size() - 2) {
                            Subject subject = subjects.get(i - 2);
                            lessonRecord.setSubject(subject.getName());
                        } else if (i == m5ORm6LessonRecordArrayList.size() - 2) {
                            lessonRecord.setSubject("自习");
                            lessonRecord.setType("/");
                        } else if (i == m5ORm6LessonRecordArrayList.size() - 1) {
                            lessonRecord.setSubject(testString);
                            lessonRecord.setType("/");
                            lessonRecord.setTime("14:00-16:00");
                            lessonRecord.setHours("/");
                            lessonRecord.setPosition("303考场");
                        }else {
                            lessonRecord.setSubject("/");
                            lessonRecord.setType("/");
                            lessonRecord.setPosition("/");
                            lessonRecord.setHours("/");
                        }
                    }
                }
            }
        }else {
            for (int i = 0; i < m5ORm6LessonRecordArrayList.size(); i++) {
                LessonRecord lessonRecord = m5ORm6LessonRecordArrayList.get(i);
                if (i < 6) {
                    lessonRecord.setSubject(subjects.get(i).getName());
                } else if (m5ORm6LessonRecordArrayList.size() == 49) {
                    if (i > 7 && i < m5ORm6LessonRecordArrayList.size() - 4) {
                        Subject subject = subjects.get(i - 2);
                        lessonRecord.setSubject(subject.getName());
                    } else if (i >= m5ORm6LessonRecordArrayList.size() - 4 && i != m5ORm6LessonRecordArrayList.size() - 1) {
                        lessonRecord.setSubject("自习");
                        lessonRecord.setType("/");
                    } else if (i == m5ORm6LessonRecordArrayList.size() - 1) {
                        lessonRecord.setSubject(testString);
                        lessonRecord.setType("/");
                        lessonRecord.setHours("/");
                        lessonRecord.setPosition("303考场");
                    }else {
                        lessonRecord.setSubject("/");
                        lessonRecord.setType("/");
                        lessonRecord.setPosition("/");
                        lessonRecord.setHours("/");
                    }
                }else {
                    if (i > 7 && i < m5ORm6LessonRecordArrayList.size() - 2) {
                        Subject subject = subjects.get(i - 2);
                        lessonRecord.setSubject(subject.getName());
                    } else if (i == m5ORm6LessonRecordArrayList.size() - 2) {
                        lessonRecord.setSubject("自习");
                        lessonRecord.setType("/");
                    } else if (i == m5ORm6LessonRecordArrayList.size() - 1) {
                        lessonRecord.setSubject(testString);
                        lessonRecord.setType("/");
                        lessonRecord.setHours("/");
                        lessonRecord.setPosition("303考场");
                    }else {
                        lessonRecord.setSubject("/");
                        lessonRecord.setType("/");
                        lessonRecord.setPosition("/");
                        lessonRecord.setHours("/");
                    }
                }
            }
        }
    }

    /**
     * 设置M3的课程安排
     * @param m3LessonRecordArrayList
     */
    private void setM3Class(ArrayList<LessonRecord> m3LessonRecordArrayList) {
        String model = "M3";
        String testString = "M3模块考试";
        List<Subject> subjects = getSubjectModel(model);
        if (!m3LessonRecordArrayList.get(0).getWeekend().equals("星期六")) {
            for (int i = 2; i < m3LessonRecordArrayList.size(); i++) {
                LessonRecord lessonRecord = m3LessonRecordArrayList.get(i);
                if (i< m3LessonRecordArrayList.size()-2) {
                    Subject subject = subjects.get(i-2);
                    lessonRecord.setSubject(subject.getName());
                }
                else if (i == m3LessonRecordArrayList.size()-2) {
                    lessonRecord.setSubject("自习");
                    lessonRecord.setType("/");
                }
                else  {
                    lessonRecord.setSubject(testString);
                    lessonRecord.setType("/");
                    lessonRecord.setHours("/");
                    lessonRecord.setPosition("303考场");
                }
            }
            for (int i = 0; i <2 ; i++) {
                LessonRecord lessonRecord = m3LessonRecordArrayList.get(i);
                lessonRecord.setSubject("/");
                lessonRecord.setType("/");
                lessonRecord.setPosition("/");
                lessonRecord.setHours("/");
            }
        }
        else {
            for (int i = 0; i < m3LessonRecordArrayList.size(); i++) {
                LessonRecord lessonRecord = m3LessonRecordArrayList.get(i);
                if (i==4||i==5) {
                    lessonRecord.setSubject("/");
                    lessonRecord.setType("/");
                    lessonRecord.setPosition("/");
                    lessonRecord.setHours("/");
                }else {
                    if (i<4) {
                        Subject subject = subjects.get(i);
                        lessonRecord.setSubject(subject.getName());
                    }else if (i < m3LessonRecordArrayList.size() - 2){
                        Subject subject = subjects.get(i-2);
                        lessonRecord.setSubject(subject.getName());
                    }else if (i == m3LessonRecordArrayList.size()-2) {
                        lessonRecord.setSubject("自习");
                        lessonRecord.setType("/");
                    } else  {
                        lessonRecord.setSubject(testString);
                        lessonRecord.setType("/");
                        lessonRecord.setHours("/");
                        lessonRecord.setPosition("303考场");
                    }
                }
            }
        }
    }

    /**
     * 设置M2的课程安排
     * @param m2LessonRecordArrayList
     * @return
     */
    private void setM2Class(ArrayList<LessonRecord> m2LessonRecordArrayList) {
        String model = "M2";
        String testString = "M2模块考试";
        List<Subject> subjects = getSubjectModel(model);
        if (!m2LessonRecordArrayList.get(0).getWeekend().equals("星期六")) {
            for (int i = 0; i < m2LessonRecordArrayList.size(); i++) {
                LessonRecord lessonRecord = m2LessonRecordArrayList.get(i);
                if (i<1) {
                    lessonRecord.setSubject("/");
                    lessonRecord.setType("/");
                    lessonRecord.setPosition("/");
                    lessonRecord.setHours("/");
                }
                else if (i< m2LessonRecordArrayList.size()-3) {
                    Subject subject = subjects.get(i);
                    lessonRecord.setSubject(subject.getName());
                }
                else if (i == m2LessonRecordArrayList.size()-1) {
                    lessonRecord.setSubject(testString);
                    lessonRecord.setType("/");
                    lessonRecord.setHours("/");
                    lessonRecord.setPosition("303考场");
                } else {
                    lessonRecord.setSubject("自习");
                    lessonRecord.setType("/");

                }
            }
        }else {
            for (int i = 0; i < m2LessonRecordArrayList.size(); i++) {
                LessonRecord lessonRecord = m2LessonRecordArrayList.get(i);
                if (i==4) {
                    lessonRecord.setSubject("/");
                    lessonRecord.setType("/");
                    lessonRecord.setPosition("/");
                    lessonRecord.setHours("/");
                }  else {
                    if (i< m2LessonRecordArrayList.size()-3) {
                        Subject subject = subjects.get(i);
                        lessonRecord.setSubject(subject.getName());
                    }
                    else if (i == m2LessonRecordArrayList.size()-1) {
                        lessonRecord.setSubject(testString);
                        lessonRecord.setType("/");
                        lessonRecord.setHours("/");
                        lessonRecord.setPosition("303考场");
                    } else {
                        lessonRecord.setSubject("自习");
                        lessonRecord.setType("/");

                    }
                }
            }
        }
    }

    /**
     * 设置M1的课程安排
     * @param m1LessonRecordArrayList
     * @return
     */
    private void setM1Class(ArrayList<LessonRecord> m1LessonRecordArrayList) {
        String model = "M1";
        String testString = "M1模块考试";
        List<Subject> subjects = getSubjectModel(model);
        for (int i = 0; i < m1LessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord = m1LessonRecordArrayList.get(i);
            if (i< m1LessonRecordArrayList.size()-1){
                Subject subject = subjects.get(i);
                lessonRecord.setSubject(subject.getName());
            }else  {
                lessonRecord.setSubject(testString);
                lessonRecord.setHours("/");
                lessonRecord.setPosition("303考场");
                lessonRecord.setType("/");
            }
        }
    }


    /**
     * 从数据库中查询各模块的课程安排
     * @param model
     */
    private List<Subject>  getSubjectModel(String model) {
        LambdaQueryWrapper<Subject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Subject::getModel, model);
        return subjectMapper.selectList(queryWrapper);
    }


    private HashMap<String,ArrayList<LessonRecord>>  writeExcelTime(String date, String type) {
          /*
        生成M1-M8的课表
        上完后的考试需要注意以下几点
        1.上完课后的第二个工作日如果是周六，则不安排进行考试，考试安排在下周一
        2.上完课后的第二个工作日如果是周六，则直接进行下个科目
        3.考试当天的其余时间也会进行上课
        4.M1-M6考试的安排时间基本都是固定的
         */
        //M1,得到M1的课程安排
        ArrayList<LessonRecord> m1LessonRecordArrayList = setM1Subject(date);

        //M1上完第二个工作日开始上M2，因此M2的开课日期应该在lastWorkdayDate往后一天
        //M2,这里M2是直接考完M1的考试就直接上课的,得到M2的课程时间安排
        HashMap<String, String> stringHashMap = getTestWorkDayAndTheTomorrow(m1LessonRecordArrayList);
        String testWorkdayDate = stringHashMap.get("testWorkdayDate");
        String theTomorrow = stringHashMap.get("theTomorrow");
        ArrayList<LessonRecord> m2LessonRecordArrayList = setM2Subject(testWorkdayDate,theTomorrow);

        //M3,这里如果M2上完后面一个工作日是周六，则M3从后面一个工作日开始，如果后面一个工作日不是周六，则M3从后面一个工作日开始
        stringHashMap = getTestWorkDayAndTheTomorrow(m2LessonRecordArrayList);
        testWorkdayDate = stringHashMap.get("testWorkdayDate");
        theTomorrow = stringHashMap.get("theTomorrow");
        ArrayList<LessonRecord> m3LessonRecordArrayList = setM3Subject(testWorkdayDate,theTomorrow);

        //这里需要判断是TA还是PA,如果TA就上M5,PA就上M6
        stringHashMap = getTestWorkDayAndTheTomorrow(m3LessonRecordArrayList);
        testWorkdayDate = stringHashMap.get("testWorkdayDate");
        theTomorrow = stringHashMap.get("theTomorrow");
        ArrayList<LessonRecord> m5ORm6LessonRecordArrayList = new ArrayList<>();
        if (type.equals("TA")) {
            m5ORm6LessonRecordArrayList =  setM5Subject(testWorkdayDate,theTomorrow);
        }else if (type.equals("PA")) {
            m5ORm6LessonRecordArrayList =  setM6Subject(testWorkdayDate,theTomorrow);
        }
        //m7
        stringHashMap = getTestWorkDayAndTheTomorrow(m5ORm6LessonRecordArrayList);
        testWorkdayDate = stringHashMap.get("testWorkdayDate");
        theTomorrow = stringHashMap.get("theTomorrow");
        ArrayList<LessonRecord> m7LessonRecordArrayList = setM7Subject(testWorkdayDate,theTomorrow);
        //M8
        stringHashMap = getTestWorkDayAndTheTomorrow(m7LessonRecordArrayList);
        theTomorrow = stringHashMap.get("theTomorrow");
        //由于M7没有考试，因此不需要考虑M7考试会影响M8上课的问题
        ArrayList<LessonRecord> m8LessonRecordArrayList = setM8Subject(theTomorrow);
        HashMap<String,ArrayList<LessonRecord>> hashMap = new HashMap<>();
        hashMap.put("m1LessonRecordArrayList", m1LessonRecordArrayList);
        hashMap.put("m2LessonRecordArrayList", m2LessonRecordArrayList);
        hashMap.put("m3LessonRecordArrayList", m3LessonRecordArrayList);
        hashMap.put("m5ORm6LessonRecordArrayList", m5ORm6LessonRecordArrayList);
        hashMap.put("m7LessonRecordArrayList", m7LessonRecordArrayList);
        hashMap.put("m8LessonRecordArrayList", m8LessonRecordArrayList);
        return hashMap;
    }



    /**
     * 在数据库中查找下一个工作日的方法
     * @param lastWorkday 这里的格式是xx月xx日的格式
     * @return
     */
    private String findTheTomorrow(String lastWorkday) {
        //获取现在的年份
        Integer nowYear = commonUtils.nowYear();
        String day = nowYear+"年"+lastWorkday;
        Date formattedDate = commonUtils.mySqlDateFormatStringOfDashToDate(day);
        ShangKeRiQi shangKeRiQi = shangKeRiQiMapper.selectTheDayAfterDayByDate(formattedDate);
        Long id = shangKeRiQi.getId();
        //由于我们数据库里id是自增的，因此寻找其后面的日期
        ShangKeRiQi riQi = shangKeRiQiMapper.findTommorow(id);
        Date riQiDate = riQi.getDate();
        String returnDate = commonUtils.mySqlDateFormatDateDashToString(riQiDate);
        returnDate = returnDate.substring(returnDate.indexOf("年")+1);
        return returnDate;
    }

    /**
     * 传入一个科目的时间安排表就能得到他考试的日期和下一个模块开班的日期
     * @param lessonRecordArrayList
     * @return
     */
    private HashMap<String,String> getTestWorkDayAndTheTomorrow(ArrayList<LessonRecord> lessonRecordArrayList) {
        int size = lessonRecordArrayList.size();
        LessonRecord testLessonRecord = lessonRecordArrayList.get(size - 1);
        String testWorkdayDate = commonUtils.mySqlDateFormatDateDashToString(testLessonRecord.getDate());
        LessonRecord lastLessonRecord = lessonRecordArrayList.get(size - 2);
        String lastWorkdayDate = commonUtils.mySqlDateFormatDateDashToString(lastLessonRecord.getDate());
        String theTomorrow = findTheTomorrow(lastWorkdayDate);
        HashMap<String,String> hashMap = new HashMap<String,String>();
        hashMap.put("testWorkdayDate",testWorkdayDate);
        hashMap.put("theTomorrow",theTomorrow);
        return hashMap;
    }



    /**
     * 生成M1的课表
     */
    private ArrayList<LessonRecord> setM1Subject(String kaiBanDate) {

        ArrayList<LessonRecord> m1LessonRecordArrayList = getWorkdaysAtM1AndM2AndM7(kaiBanDate,17, 16, "9:30-10:10");
        return m1LessonRecordArrayList;
    }

    /**
     * 生成M2的课表
     * @param startM2Date 开始M2的日期
     * * @param testWorkdayDate 考M1的时候正在上M2，此时M2是不上课的
     * @return
     */
    private ArrayList<LessonRecord> setM2Subject(String testWorkdayDate, String startM2Date) {
        //获取现在的年份
        Integer nowYear = commonUtils.nowYear();
        startM2Date=nowYear+"年"+startM2Date;
        ArrayList<LessonRecord> m2LessonRecordArrayList = getWorkdaysAtM1AndM2AndM7(startM2Date,  29, 28, "10:00-11:30");
        //找到m1WorkdayArrayList中date是testWorkdayDate的workday
        // 遍历 ArrayList，查找目标对象的属性值
        for (int i = 0; i < m2LessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord1 = m2LessonRecordArrayList.get(i);
            Date date1 = lessonRecord1.getDate();
            String date = commonUtils.mySqlDateFormatDateDashToString(date1);
            String time = lessonRecord1.getTime();
            System.out.println(time);
            if (date.equals(testWorkdayDate)&&(time.equals("8:30-10:30"))) {
                System.out.println("找到目标对象，姓名：" + date);
                lessonRecord1.setSubject("/");
                break;
            }
        }
        return m2LessonRecordArrayList;
    }




    /**
     * 生成M3的课表
     * @param startM3Date 开始M3的日期
     * @param testWorkdayDate 考M2的时候正在上M3，此时M3上午是不上课的，要将M3从课表中去除掉
     * @return
     */
    private ArrayList<LessonRecord> setM3Subject(String testWorkdayDate, String startM3Date) {
        //获取现在的年份
        ArrayList<LessonRecord> m3LessonRecordArrayList = getWorkDaysFromMysql(startM3Date, 93, 92, "14:00-17:30", "下午");
        //找到m3WorkdayArrayList中date是testWorkdayDate的workday
        // 遍历 ArrayList，查找目标对象的属性值
        int deleteNum = 0;
        for (int i = 0; i < m3LessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord1 = m3LessonRecordArrayList.get(i);
            if (lessonRecord1.getDate().equals(testWorkdayDate)&&(lessonRecord1.getMorningOrAfternoon().equals("上午"))) {
                System.out.println("找到目标对象，姓名：" + lessonRecord1.getDate());
                lessonRecord1.setSubject("/");
                deleteNum++;
                if (deleteNum == 2) {
                    break;
                }
            }
        }
        return m3LessonRecordArrayList;
    }

    /**
     * 生成M5的课表
     * @param startM5Date 开始M5的日期
     * @param testWorkdayDate 考M2的时候正在上M3，此时M3上午是不上课的，要将M3从课表中去除掉
     * @return
     */
    private ArrayList<LessonRecord> setM5Subject(String testWorkdayDate, String startM5Date) {
        Integer lessons = 47;
        ArrayList<LessonRecord> m5LessonRecordArrayList = getWorkDaysFromMysqlForM5(startM5Date, lessons, 46, "14:00-16:00", "上午");
        // 遍历 ArrayList，查找目标对象的属性值
        int deleteNum = 0;
        for (int i = 0; i < m5LessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord1 = m5LessonRecordArrayList.get(i);
            if (lessonRecord1.getDate().equals(testWorkdayDate)&&(lessonRecord1.getMorningOrAfternoon().equals("下午"))) {
                System.out.println("找到目标对象，姓名：" + lessonRecord1.getDate());
                lessonRecord1.setSubject("/");
                deleteNum++;
                if (deleteNum == 2) {
                    break;
                }
            }
        }
        return m5LessonRecordArrayList;
    }



    /**
     * 生成M3的课表
     * @param startM6Date 开始M6的日期
     * @param testWorkdayDate 考M2的时候正在上M3，此时M3上午是不上课的，要将M3从课表中去除掉
     * @return
     */
    private ArrayList<LessonRecord> setM6Subject(String testWorkdayDate, String startM6Date) {
        Integer lessons = 33;
        ArrayList<LessonRecord> m6LessonRecordArrayList = getWorkDaysFromMysql(startM6Date, lessons, 32, "10:00-11:30", "上午");
        //找到m3WorkdayArrayList中date是testWorkdayDate的workday
        // 遍历 ArrayList，查找目标对象的属性值
        int deleteNum = 0;
        for (int i = 0; i < m6LessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord1 = m6LessonRecordArrayList.get(i);
            if (lessonRecord1.getDate().equals(testWorkdayDate)&&(lessonRecord1.getMorningOrAfternoon().equals("下午"))) {
                System.out.println("找到目标对象，姓名：" + lessonRecord1.getDate());
                lessonRecord1.setSubject("/");
                deleteNum++;
                if (deleteNum == 2) {
                    break;
                }
            }
        }
        return m6LessonRecordArrayList;
    }

    /**
     * 生成M7的课表
     * @param startM7Date 开始M7的日期
     * @param testWorkdayDate 考M6的日期
     * @return
     */
    private ArrayList<LessonRecord> setM7Subject(String testWorkdayDate, String startM7Date) {
        //获取现在的年份
        Integer nowYear = commonUtils.nowYear();
        startM7Date=nowYear+"年"+startM7Date;
        ArrayList<LessonRecord> lessonRecordArrayList = setSubjectTime(startM7Date, 92);
        int deleteNum = 0;
        for (int i = 0; i < lessonRecordArrayList.size(); i++) {
            LessonRecord lessonRecord1 = lessonRecordArrayList.get(i);
            if (lessonRecord1.getDate().equals(testWorkdayDate)&&(lessonRecord1.getMorningOrAfternoon().equals("上午"))) {
                System.out.println("找到目标对象，姓名：" + lessonRecord1.getDate());
                lessonRecord1.setSubject("/");
                deleteNum++;
                if (deleteNum == 2) {
                    break;
                }
            }
        }
        return lessonRecordArrayList;
    }

    /**
     * 生成M8的课表
     * @param startM8Date 开始M8的日期
     * @return
     */
    private ArrayList<LessonRecord> setM8Subject(String startM8Date) {
        //M7没有考试时间
        //获取现在的年份
        Integer nowYear = commonUtils.nowYear();
        startM8Date=nowYear+"年"+startM8Date;
        return setSubjectTime(startM8Date, 64);
    }

    /**
     * 因为M5是上完当天今天考试，有点不一样，这个是专门给M5写的从数据库获取时间安排的方法
     * @param startDate 开始上M5的日期
     * @param lessons 上课的课时（包括考试课时）
     * @param lessonMinusOne 课时减1，方便计算考试时间
     * @param testTime 考试具体时间
     * @param morningOrAfternoon 考试是在上午还是在下午
     * @return
     */
    private ArrayList<LessonRecord> getWorkDaysFromMysqlForM5(String startDate, Integer lessons, int lessonMinusOne, String testTime, String morningOrAfternoon) {
        Integer nowYear = commonUtils.nowYear();
        startDate = nowYear + "年" + startDate;
        ArrayList<LessonRecord> lessonRecordArrayList = setSubjectTime(startDate, lessons);
        LessonRecord lessonRecord = lessonRecordArrayList.get(lessonMinusOne);
        String weekend = lessonRecord.getWeekend();
        if (weekend.equals("星期六")) {//最后是用来考试的日期，考试不能安排在周六
            LessonRecord lessonRecord1 = new LessonRecord();
            LessonRecord lessonRecord2 = new LessonRecord();
            lessonRecord2.setTime("15:30-17:30");
            lessonRecord2.setType("理论");
            lessonRecord2.setHours("2");
            lessonRecord2.setMorningOrAfternoon("下午");
            lessonRecord2.setPosition("301");
            lessonRecord2.setWeekend(lessonRecordArrayList.get(lessonRecordArrayList.size()-1).getWeekend());
            lessonRecord2.setDate(lessonRecordArrayList.get(lessonRecordArrayList.size()-1).getDate());
            lessonRecordArrayList.add(lessonRecord2);
            String date = commonUtils.mySqlDateFormatDateDashToString(lessonRecord.getDate());
            date = nowYear+"年"+date;
            //将xxxx年xx月xx日转变成xxxx-xx-xx的格式,且这个格式是Date属性
            Date formattedDate = commonUtils.mySqlDateFormatStringOfDashToDate(date);
            //需要从数据库中查询到给定这一天后面一个工作日是哪一天
            ShangKeRiQi shangKeRiQi = shangKeRiQiMapper.selectTheDayAfterDayByDate(formattedDate);
            Long id = shangKeRiQi.getId();
            //由于我们数据库里id是自增的，因此寻找其后面的日期
            ShangKeRiQi riQi = shangKeRiQiMapper.findTommorow(id);
            String formatDateToString = commonUtils.mySqlDateFormatDateDashToString(riQi.getDate());
            String substring = formatDateToString.substring(formatDateToString.indexOf("年")+1);
            lessonRecord1.setDate(commonUtils.mySqlDateFormatStringOfDashToDate(substring));
            lessonRecord1.setWeekend(riQi.getWeekend());
            lessonRecord1.setMorningOrAfternoon("下午");
            lessonRecord1.setTime("14:00-16:00");
            lessonRecord1.setHours("2");
            lessonRecord1.setType("考试");
            lessonRecordArrayList.add(lessonRecord1);
        }
        return lessonRecordArrayList;
    }

    /*
            workday.setWeekend("星期一");
        String date = workday.getDate();
        date = nowYear+"年"+date;
//            //将xxxx年xx月xx日转变成xxxx-xx-xx的格式,且这个格式是Date属性
        Date formattedDate = commonUtils.mySqlDateFormatStringToDate(date);
        //需要从数据库中查询到给定这一天后面一个工作日是哪一天
        ShangKeRiQi shangKeRiQi = shangKeRiQiMapper.selectTheDayAfterDayByDate(formattedDate);
        Long id = shangKeRiQi.getId();
        //由于我们数据库里id是自增的，因此寻找其后面的日期
        ShangKeRiQi riQi = shangKeRiQiMapper.findTommorow(id);
        String formatDateToString = commonUtils.mySqlDateFormatDateToString(riQi.getDate());
        String substring = formatDateToString.substring(formatDateToString.indexOf("年")+1);
        workday.setDate(substring);
     */

    /**
     *
     * @param startDate 开始上课的日期
     * @param lessons 上课的课时（包括考试课时）
     * @param lessonMinusOne 课时减1方便计算考试日期
     * @param testTime 考试具体时间
     * @param morningOrAfternoon 考试是在上午还是在下午
     * @return
     */
    private ArrayList<LessonRecord> getWorkDaysFromMysql(String startDate, Integer lessons, int lessonMinusOne, String testTime, String morningOrAfternoon) {
        Integer nowYear = commonUtils.nowYear();
        startDate = nowYear + "年" + startDate;
        ArrayList<LessonRecord> lessonRecordArrayList = setSubjectTime(startDate, lessons);
        LessonRecord lessonRecord = lessonRecordArrayList.get(lessonMinusOne);
        lessonRecord.setTime(testTime);
        lessonRecord.setMorningOrAfternoon(morningOrAfternoon);
        String weekend = lessonRecord.getWeekend();
        if (weekend.equals("星期六")) {//最后是用来考试的日期，考试不能安排在周六
            ifTheDayIsSaturaday(nowYear, lessonRecord);
        }
        return lessonRecordArrayList;
    }

    /**
     *
     * @param startDate 开班的日期
     * @param lessons 上课时间
     * @param lessonMinusOne 上课时间-1,方便计算考试日期
     * @param testTime 考试时间
     * @return
     */
    private ArrayList<LessonRecord> getWorkdaysAtM1AndM2AndM7(String startDate, int lessons, int lessonMinusOne, String testTime) {
        //获取现在的年份
        Integer nowYear = commonUtils.nowYear();
        ArrayList<LessonRecord> lessonRecordArrayList = setSubjectTime(startDate, lessons);
        LessonRecord lessonRecord = lessonRecordArrayList.get(lessonMinusOne);
        String weekend = lessonRecord.getWeekend();
        lessonRecord.setTime(testTime);
        if (weekend.equals("星期六")) {//最后是用来考试的日期，考试不能安排在周六
            ifTheDayIsSaturaday(nowYear, lessonRecord);
        }
        return lessonRecordArrayList;
    }



    /**
     * 根据传入的哪门课生成该班的课程时间安排
     * @param kaiBanDate 传入的是M1-M8
     * @param lessons 该门课的节数
     * @return
     */
    private ArrayList<LessonRecord> setSubjectTime(String kaiBanDate, int lessons) {
        //从数据库中查询到工作日的列表
        LambdaQueryWrapper<ShangKeRiQi> queryWrapper = new LambdaQueryWrapper<>();
        List<ShangKeRiQi> shangKeRiQis = shangKeRiQiMapper.selectList(queryWrapper);
        ArrayList<LessonRecord> lessonRecordArrayList = new ArrayList<>();
        shangKeRiQis.forEach(a -> {
            Date date = a.getDate();
            String formattedDate = commonUtils.mySqlDateFormatDateDashToString(date);
            //从传入的日期后面开始排
            if (commonUtils.afterDay(formattedDate,kaiBanDate)) {
                int year = formattedDate.indexOf("年");
                String newDate = formattedDate.substring(year+1);
                for (int i = 0; i < 4; i++) {
                    LessonRecord lessonRecord = new LessonRecord();
                    lessonRecord.setDate(commonUtils.mySqlDateFormatStringOfDashToDate(newDate));
                    lessonRecord.setWeekend(a.getWeekend());
                    lessonRecord.setHours("2");
                    lessonRecord.setPosition("301");
                    lessonRecord.setType("理论");
                    if (i<2){
                        //设置excel的时间
                        lessonRecord.setMorningOrAfternoon("上午");
                        if (i==0){
                            lessonRecord.setTime("8:30-10:30");
                        }else {
                            lessonRecord.setTime("10:30-12:30");
                        }
                    }else {
                        lessonRecord.setMorningOrAfternoon("下午");
                        if (i==2){
                            lessonRecord.setTime("13:30-15:30");
                        }else {
                            lessonRecord.setTime("15:30-17:30");
                        }
                    }
                    if (lessonRecordArrayList.size()<lessons) {
                        lessonRecordArrayList.add(lessonRecord);
                    }
                }
            }
        });
        return lessonRecordArrayList;
    }


    /**
     * 假如传进来的workday是周六，则将其推到改日后面的一个工作日，因为周六不安排考试
     * @param nowYear
     * @param lessonRecord
     */
    private void ifTheDayIsSaturaday(Integer nowYear, LessonRecord lessonRecord) {
        Date date1 = lessonRecord.getDate();
//        date = nowYear+"年"+date;
        String date = commonUtils.mySqlDateFormatDateDashToString(date1);
//            //将xxxx年xx月xx日转变成xxxx-xx-xx的格式,且这个格式是Date属性
        Date formattedDate = commonUtils.mySqlDateFormatStringOfDashToDate(date);
        //需要从数据库中查询到给定这一天后面一个工作日是哪一天
        ShangKeRiQi shangKeRiQi = shangKeRiQiMapper.selectTheDayAfterDayByDate(formattedDate);
        Long id = shangKeRiQi.getId();
        //由于我们数据库里id是自增的，因此寻找其后面的日期
        ShangKeRiQi riQi = shangKeRiQiMapper.findTommorow(id);
        String formatDateToString = commonUtils.mySqlDateFormatDateDashToString(riQi.getDate());
        String substring = formatDateToString.substring(formatDateToString.indexOf("年")+1);
        lessonRecord.setDate(commonUtils.mySqlDateFormatStringOfDashToDate(substring));
        lessonRecord.setWeekend(riQi.getWeekend());
    }

}
